/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cmp.player;

import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import java.io.IOException;

/**
 * A object to contain selectable stats.
 * @author Krummer
 */
public class PlayerStats implements Savable {
    public static final float DEFAULT = 100.f; //for easy percentage calc.
    public PlayerFactory.Role role;
    public float health, energy, speed, damage;
    
    /**
     * Pick the default value for everything.
     */
    public PlayerStats() {
        this.role = PlayerFactory.Role.BRAWLER;
        this.damage = DEFAULT;
        this.speed = DEFAULT;
        this.energy = DEFAULT;
        this.health = DEFAULT;
    }
    
    public PlayerStats(PlayerFactory.Role role, float health, float energy, float speed, float damage) {
        this.role = role;
        this.damage = damage;
        this.speed = speed;
        this.energy = energy;
        this.health = health;
    }

    public void write(JmeExporter ex) throws IOException {
        OutputCapsule capsule = ex.getCapsule(this);
        capsule.write(role,    "Role",   PlayerFactory.Role.BRAWLER);
        capsule.write(health,  "Health", DEFAULT);
        capsule.write(energy,  "Energy", DEFAULT);
        capsule.write(speed,   "Speed",  DEFAULT);
        capsule.write(damage,  "Damage", DEFAULT);
    }

    public void read(JmeImporter im) throws IOException {
        InputCapsule capsule = im.getCapsule(this);
        Integer roleOrdinal = capsule.readInt("Role",   PlayerFactory.Role.BRAWLER.ordinal());
        this.role = PlayerFactory.Role.values()[roleOrdinal];
        
        this.health = capsule.readFloat("Health",DEFAULT);
        this.energy = capsule.readFloat("Energy",DEFAULT);
        this.speed = capsule.readFloat( "Speed", DEFAULT);
        this.damage = capsule.readFloat("Damage",DEFAULT);
    }
}
